package cn.io1;

import java.io.*;

/**
 * 打印流
 */
public class Test08 {
    public static void main(String[] args) {
        method01();
        // method02();
        // method03();
        // method05();
    }

    private static void method05() {
        try(PrintStream ps = new PrintStream("move/c.txt")){
            ps.print(97);
            ps.println(97);
            ps.print(23.3f);
            ps.print("\n");
            ps.println(true);
            ps.println(false);
            ps.println('a');
            ps.println("abc");
            ps.println(12.3);
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    private static void method03() {
        try(PrintStream ps = new PrintStream("move/d.txt", "gbk")){
            ps.println("大家好");
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    /*
        PrintStream的基本使用

        1. 创建对象关联文件
                public PrintStream (OutputStream os)
                public PrintStream (File f)
                public PrintStream (File f, String csn)
                public PrintStream (String filepath)
                public PrintStream (String filepath, String csn)

        2. 写出方法
                write() : 写出一个字节, 不建议使用, 无法原样写入.
                print() : 原样写入数据, 无换行
                println() : 原样写入数据, 带有换行
     */
    private static void method02() {
        try(PrintStream ps = new PrintStream(new FileOutputStream("move/f.txt", true))) {
            ps.println("你好");
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    private static void method01() {
        System.out.println("你好");
        System.err.println("哈哈");
        try(PrintWriter pwd = new PrintWriter(new FileWriter("move/a.txt"), true)){
            pwd.println("你好");
            pwd.println(false);
        }catch (IOException e){
            e.printStackTrace();
        }
    }
}
